namespace Framework.Utils.SingletonTemplate
{
    public abstract class SingletonBase<T , Tbase>  where T : new() where Tbase : SingletonBase<T , Tbase> , new()
    {
        static Tbase _baseObject;
        protected static T _instance;
        
        public static T Instance
        {
            get
            {
                if (_instance == null)
                {
                    _baseObject = new Tbase();
                    _instance = _baseObject.CreateInstance();
                    _baseObject.OnInit();
                }
                return _instance;
            }
        }

        protected virtual T CreateInstance()
        {
            return  new T();
        }

        protected virtual void OnInit() { }

    }
}